export default {
  data() {
    return {
      address: "",
      point: {},
      city: "",
    };
  },
  activated() {
    this.ready();
  },
  methods: {
    ready() {
      let myLocation = JSON.parse(localStorage.getItem("myLocation"));
      // let myLocation = this.$store.state.o2oLocation;
      console.log(myLocation,'myLocationmyLocation');

      if (myLocation && myLocation.point) {
        this.address = myLocation.title;
        this.city = myLocation.city;
        this.point = myLocation.point;
        //初始化数据
      } else {
        // 防止首页空白定位前先请求一下接口
        console.log("location不存在");
        this.fun.getLocation()
          .then((res)=> {
            this.point = res.point;
            this.address = res.title;
            this.city = res.city;
          })
          .catch((err)=> {
            console.log(err);
          });
      }
    },
    tolocation() {
      this.$store.commit("setReferer", window.location.href);
      this.$router.push(this.fun.getUrl("o2oLocation_loc", { fromHome: 1 }));
    },
    // 搜索页面
    tosearch() {
      this.$router.push(
        this.fun.getUrl("anytimeSearch", {})
      );
    }
  },
  components: {  }
};
